package com.itstudio.portal.service.impl;

import com.itstudio.portal.entity.UserInfo;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service("ps")
public class PermissionServiceImpl {
    public boolean hasPermission(String permission) {
        Object object = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(!(object instanceof UserInfo))
            return false;
        UserInfo userInfo = (UserInfo) object;
        return userInfo.getPermissions().contains(permission);
    }
}
